/*
 *  TwitterWhatAreYouDoingService
 *
 * Created on September 2, 2008, 8:33 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.netbeans.saas.twitter;

import java.io.IOException;
import org.netbeans.saas.RestConnection;
import org.netbeans.saas.RestResponse;

/**
 * TwitterWhatAreYouDoingService Service
 *
 * @author hulles
 */

public class TwitterWhatAreYouDoingService {

    /** Creates a new instance of TwitterWhatAreYouDoingService */
    public TwitterWhatAreYouDoingService() {
    }

    /**
     * Retrieves representation of an instance of webtest.GetFriendsTimelineResource
     * @param since resource URI parameter
     * @param sinceId resource URI parameter
     * @param page resource URI parameter
     * @param format resource URI parameter
     * @return an instance of RestResponse
     */
    public static RestResponse getFriendsTimeline(String since, String sinceId, String page, String format) throws IOException {
        TwitterWhatAreYouDoingServiceAuthenticator.login();

        String[][] pathParams = new String[][]{{"{format}", format}};
        String[][] queryParams = new String[][]{{"since", since}, {"since_id", sinceId}, {"page", page}};
        RestConnection conn = new RestConnection("http://twitter.com/statuses/friends_timeline.{format}", pathParams, queryParams);

        return conn.get(null);
    }
    

    /**
     * Retrieves representation of an instance of webtest.GetUserTimelineResource
     * @param since resource URI parameter
     * @param sinceId resource URI parameter
     * @param page resource URI parameter
     * @param count resource URI parameter
     * @param format resource URI parameter
     * @return an instance of RestResponse
     */
    public static RestResponse getUserTimeline(String since, String sinceId, String page, String format) throws IOException {
        TwitterWhatAreYouDoingServiceAuthenticator.login();

        String[][] pathParams = new String[][]{{"{format}", format}};
        String[][] queryParams = new String[][]{{"since", since}, {"since_id", sinceId}, {"page", page}};
        RestConnection conn = new RestConnection("http://twitter.com/statuses/user_timeline.{format}", pathParams, queryParams);

        return conn.get(null);
    }

    /**
     * Retrieves representation of an instance of webtest.GetDirectMessagesToMeResource
     * @param since resource URI parameter
     * @param sinceId resource URI parameter
     * @param page resource URI parameter
     * @param format resource URI parameter
     * @return an instance of RestResponse
     */
    public static RestResponse getDirectMessagesToMe(String since, String sinceId, String page, String format) throws IOException {
        TwitterWhatAreYouDoingServiceAuthenticator.login();

        String[][] pathParams = new String[][]{{"{format}", format}};
        String[][] queryParams = new String[][]{{"since", since}, {"since_id", sinceId}, {"page", page}};
        RestConnection conn = new RestConnection("http://twitter.com/direct_messages.{format}", pathParams, queryParams);

        return conn.get(null);
    }

    /**
     * Retrieves representation of an instance of webtest.GetRepliesResource
     * @param since resource URI parameter
     * @param sinceId resource URI parameter
     * @param page resource URI parameter
     * @param format resource URI parameter
     * @return an instance of RestResponse
     */
    public static RestResponse getReplies(String since, String sinceId, String page, String format) throws IOException {
        TwitterWhatAreYouDoingServiceAuthenticator.login();

        String[][] pathParams = new String[][]{{"{format}", format}};
        // NOTE: differs from the NetBeans saas insert 
//        String[][] queryParams = new String[][]{{"page", page}};
        String[][] queryParams = new String[][]{{"since", since}, {"since_id", sinceId}, {"page", page}};
        RestConnection conn = new RestConnection("http://twitter.com/statuses/replies.{format}", pathParams, queryParams);

        return conn.get(null);
    }

    /**
     * Retrieves representation of an instance of webtest.EndSessionResource
     * @return an instance of RestResponse
     */
    public static RestResponse endSession() throws IOException {
        TwitterWhatAreYouDoingServiceAuthenticator.login();

        RestConnection conn = new RestConnection("http://twitter.com/account/end_session");

        return conn.get(null);
    }

    /**
     * Retrieves representation of an instance of webtest.UpdateStatusResource
     * @param status resource URI parameter
     * @param format resource URI parameter
     * @return an instance of RestResponse
     */
    public static RestResponse updateStatus(String status, String format) throws IOException {
        TwitterWhatAreYouDoingServiceAuthenticator.login();

        String[][] pathParams = new String[][]{{"{format}", format}};
        String[][] queryParams = new String[][]{{"status", status}};
        RestConnection conn = new RestConnection("http://twitter.com/statuses/update.{format}", pathParams, queryParams);

        return conn.post(null, queryParams);
    }
    

    /**
     * Retrieves representation of an instance of webtest.VerifyCredentialsResource
     * @param format resource URI parameter
     * @return an instance of RestResponse
     */
    public static RestResponse verifyCredentials(String format) throws IOException {
        TwitterWhatAreYouDoingServiceAuthenticator.login(true);

        String[][] pathParams = new String[][]{{"{format}", format}};
        RestConnection conn = new RestConnection("http://twitter.com/account/verify_credentials.{format}", pathParams, null);

        return conn.get(null);
    }
}
